import json
from dataclasses import dataclass, asdict
from typing import Optional
from pydantic import BaseModel


class PortraitStypeRepaint:
    """人像风格重绘
    """

    class Input(BaseModel):
        image_url: str
        style_index: Optional[int] = None
        style_ref_url: Optional[str] = None

        def __str__(self) -> str:
            return json.dumps(asdict(self), ensure_ascii=False)

    class PortraitStypeRepaintRequest(BaseModel):
        model: str = "wanx-style-repaint-v1"
        input: 'PortraitStypeRepaint.Input'

        # todo swagger示例
        class Config:
            schema_extra = {
                "example": {
                    "input": {
                        "image_url": "https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/public/dashscope/test.png",
                        "style_index": 3,
                        "style_ref_url": "https://example.com/style.jpg"  # 添加这个字段
                    },
                    "model": "wanx-style-repaint-v1"
                }
            }


class OutPainting:
    """图像画面扩展
    """
    @dataclass
    class Input:
        image_url: str

        def __str__(self) -> str:
            return json.dumps(asdict(self), ensure_ascii=False)

    @dataclass
    class Parameter:
        angle: int = 0
        output_ratio: str = ""
        x_scale: float = "1.0"
        y_scale: float = "1.0"
        top_offset: int = 0
        bottom_offset: int = 0
        left_offset: int = 0
        right_offset: int = 0
        best_quality: bool = False
        limit_image_size: bool = True
        add_watermark: bool = True

        def __str__(self) -> str:
            return json.dumps(asdict(self), ensure_ascii=False)

    class OutPaintingRequest(BaseModel):
        model: str = "image-out-painting"
        input: 'OutPainting.Input'
        parameters: Optional['OutPainting.Parameter'] = None  # 可以是 None
